using UnityEngine;

public class CashItem : MonoBehaviour
{
	private int step;

	private double cash;

	private float speed;

	private Vector3 firstTarget;

	private Transform lastTarget;

	[SerializeField]
	private float lastSpeed;

	[SerializeField]
	private float firstSpeed;

	public void Initialize(double cash, Vector3 firstTarget, Transform lastTarget)
	{
		this.cash = cash;
		this.lastTarget = lastTarget;
		this.firstTarget = firstTarget;
		speed = firstSpeed;
		step = 1;
	}

	private void Update()
	{
		if (step == 0)
		{
			return;
		}
		if (step == 1)
		{
			base.transform.position = Vector3.Slerp(base.transform.position, firstTarget, Time.deltaTime * speed);
			if (Vector3.Distance(base.transform.position, firstTarget) < 0.2f)
			{
				speed = lastSpeed;
				step = 2;
			}
		}
		else if (step == 2)
		{
			base.transform.position = Vector3.Slerp(base.transform.position, lastTarget.position, Time.deltaTime * speed);
			if (Vector3.Distance(base.transform.position, lastTarget.position) < 0.2f)
			{
				step = 0;
				Controller.instance.SetCash(cash);
				Sound.instance.Play("Cash");
				base.gameObject.SetActive(value: false);
			}
		}
	}
}
